<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>pictureManger</title>
    <link href="${pageContext.request.contextPath}/css/base.css" type="text/css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/tab.css" type="text/css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/item.css" type="text/css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/item_do.css" type="text/css" rel="stylesheet">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/uploadify.css" type="text/css"></link>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.uploadify.v2.0.3.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/swfobject.js"></script>
<body style="margin:1px;" id="ff">
<table id="dg"  class="easyui-datagrid" pagination="true"
       rownumbers="false" fit="true" data-options="pageSize:10"
       url="${pageContext.request.contextPath}/cooperation/search"
       toolbar="#tb" style="overflow-x: scroll;">
    <thead data-options="frozen:false">
    <tr>
        <th field="cb" checkbox="true" align="center"></th>
        <th field="id" width="100%" align="center" hidden="true">编号</th>
        <th field="requirementId" width="150" align="center">需求ID</th>
        <th field="requirementName" width="300" align="center">需求名称</th>
        <th field="requirer" width="150" align="center">需求方ID</th>
        <th field="provider" width="150" align="center">技术方ID</th>
        <th field="cooperWill" width="300" align="center">合作意愿</th>
        <th field="consult" width="150" align="center">咨询信息</th>
    </tr>
    </thead>
</table>
<div id="tb">
    <div>
         <a
            href="javascript:openPictureModifyDialog()"
            class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
         <a
            href="javascript:deleteAct()" class="easyui-linkbutton"
            iconCls="icon-remove" plain="true">删除</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog"
     style="width: 800px;height:550px;padding: 10px 20px; position: relative; z-index:1000;"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" enctype="multipart/form-data">
        <div style="padding-top:10px;  float:left; width:95%; padding-left:30px;">
            <div id="i_do_wrap">

                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">需求名称</p>
                    <input type="hidden" id="cooperid" name="id"/>
                    <input type="text" id="requirementName" name="requirementName"
                           style="border:1px #9c9c9c solid;height:25px;" disabled="disabled"/>
                </div>
                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">技术方</p>
                    <input type="text" id="provider" name="provider"
                           style="border:1px #9c9c9c solid;height:25px;" />
                </div>
                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">合作意愿</p>
                    <input type="text" id="cooperWill" name="cooperWill"
                           style="border:1px #9c9c9c solid;height:25px;" />
                </div>
                <div class="i_do_div rel">
                    <p class="i_do_tle r_txt abs font14">咨询信息</p>
                    <textarea style="font-size: 16px" rows="15" cols="50" id="consult" name="consult"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:saveAct()" class="easyui-linkbutton"
       iconCls="icon-ok">保存</a> <a href="javascript:closePictureDialog()"
                                   class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>


</body>
<script type="text/javascript">
    var url;
    var method;

    function searchPicture() {
        $("#dg").datagrid('load', {
            "url": $("#url").val(),
        });
    }

    function deleteAct() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要删除的数据！");
            return;
        }
        var strIds = [];
        for (var i = 0; i < selectedRows.length; i++) {
            strIds.push(selectedRows[i].id);
        }
        var ids = strIds.join(",");
        $.messager.confirm("系统提示", "您确认要删除这<font color=red>"
                + selectedRows.length + "</font>条数据吗？", function (r) {
            if (r) {
                $.ajax({
                    type: "GET",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/cooperation/delete/" + ids,//url
                    data: {},
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                           
                            $("#dg").datagrid(
                                    "reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "数据删除失败！");
                        }

                        ;
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });
    }


    function saveAct() {
    	var id=$("#cooperid").val();
        var provider=$("#provider").val();
        var cooperWill=$("#cooperWill").val();
        var consult=$("#consult").val();
        var data = {"id": id, "provider": provider,"cooperWill":cooperWill, "consult": consult};
        $.ajax({
            type: method,
            dataType: "json",
            url: url,
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(data),
            success: function (result) {
                console.log(result);//打印服务端返回的数据
                if (result.resultCode == 200) {
                    $.messager.alert("系统提示", "保存成功");
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                    resetValue();
                }
                else {
                    $.messager.alert("系统提示", "操作失败");
                    $("#dlg").dialog("close");
                    resetValue();
                }
            },
            error: function () {
                $.messager.alert("系统提示", "操作失败");
            }
        });
    }

    function openPictureModifyDialog() {
        var selectedRows = $("#dg").datagrid('getSelections');
        var row = selectedRows[0];
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要编辑的数据！");
            return;
        }
        $("#dlg").dialog("open").dialog("setTitle", "活动修改");
        $('#fm').form('load', row);
        $("#cooperid").val(row.id);
        method = "POST";
        url="/cooperation/update";
    }


    function resetValue() {
    	$("#cooperid").val('');
        $("#requirementName").val('');
        $("#provider").val('');
        $("#cooperWill").val('');
        $("#consult").val('');
    }

    function closePictureDialog() {
        $("#dlg").dialog("close");
        resetValue();
    }
</script>
</head>

</html>